#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>

int main(int argc, char *argv[])
{
	double h[2] = {0.01, 0.005};
	double E1,E2,E3;
	std::ofstream out_E("Exercise8.14.txt");
	double E[6];
	for(int i = 0; i != 2; i++) {
		E1 = (sin(1 + h[i]) - sin(1))/h[i] - cos(1);
		E2 = (sin(1) - sin(1 - h[i]))/h[i] - cos(1);
		E3 = (sin(1 + h[i]) - sin(1 - h[i]))/(2*h[i]) - cos(1);
		E[i*3] = E1;
		E[i*3 + 1] = E2;
		E[i*3 + 2] = E3;
		out_E << h[i] << '\t' << std::scientific << E1 << '\t' << E2 << '\t' << E3 << std::endl;
		out_E << std::fixed;
		out_E.unsetf(std::ios::fixed);
	}
	out_E << "order" << '\t' << log2(E[0]/E[3]) << '\t' << log2(E[1]/E[4]) << '\t' << log2(E[2]/E[5]) << std::endl;
	out_E.close();
	return 0;
}

